package com.aaronprj.common.utils;

import com.aaronprj.common.enums.IEnumValueName;

public final class EnumHelper {
	/**
	 * private default contructor.
	 */
	private EnumHelper() {
		super();
	}
	
	/**
	 * Retrieves the Enum constant given its numeric value.
	 * 
	 * @param <T>
	 *            Type of the enum
	 * 
	 * @param enumType
	 *            The class representing the enum in question
	 * @param intValue
	 *            The integer constant
	 * @return The Enum constant
	 */
	public static <T extends IEnumValueName> T getEnumValue(Class<T> enumType, int intValue) {
		for (T enumConstant : enumType.getEnumConstants()) {
			if (enumConstant.getValue() == intValue) {
				return enumConstant;
			}
		}
		
		return null;
	}
	
	
	/**
	 * Retrieves the Enum constant given its display name.
	 * 
	 * @param <T>
	 *            Type of the enum
	 * 
	 * @param enumType
	 *            The class representing the enum in question
	 * @param String
	 *            The string constant
	 * @return The Enum constant
	 */
	public static <T extends IEnumValueName> T getEnumValue(Class<T> enumType, String displayName) {
		for (T enumConstant : enumType.getEnumConstants()) {
			if (enumConstant.getDisplayName().equals(displayName)) {
				return enumConstant;
			}
		}
		
		return null;
	}
}
